package com.diandi.utils;

import org.springframework.util.StringUtils;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * Created by 袁恩光 on 2017/12/26.
 */
public class Md5Util {

    /**
     * 将字符串进行MD5加密
     */
    public static String md5(String value) {
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] bytes = messageDigest.digest(value.getBytes("UTF-8"));
            return new BigInteger(1, bytes).toString(16);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * md5大写
     */
    public static String md5UpperCase(String value) {
        return md5(value).toUpperCase();
    }

}
